<template>
  <a-modal
    title="选择要导入的模板"
    :width="600"
    :visible="visibleImport"
    @ok="importXlsOk"
    :confirmLoading="confirmImportLoading"
    @cancel="importXlsErr"
  >
    <a-spin :spinning="spinningImportLoading">
      <a-row class="model-row" type="flex" justify="center">
        <a-col :span="22" class="model-label">
          <a-upload
            name="file"
            :showUploadList="false"
            :multiple="false"
            :beforeUpload="beforeUpload"
          >
            <a-button type="primary" icon="import">选择文件</a-button>
          </a-upload>
          <div v-if="fileName" class="show-file">
            <a-icon class="file-icon" type="paper-clip" />
            <span>{{fileName}}</span>
            <a-icon class="file-icon file-icon-close" type="close" @click="hideFileName" />
          </div>
        </a-col>
      </a-row>
    </a-spin>
  </a-modal>
</template>

<script>
import EpaWeekly from '@/myService/EpaWeekly'

export default {
  name: 'uploadExcel',
  data() {
    return {
      reportId:null,
      visibleImport: false,
      confirmImportLoading: false,
      spinningImportLoading: false,
      uploadInfo: null,
      importChecked: false,
      file: null,
      fileName: ''
    }
  },
  methods: {
    // 是否同步设备信息
    handleCheck(e) {
      this.importChecked = e.target.checked
    },
    // 确定导入
    importXlsOk() {
      if (!this.file) {
        this.$message.error('请选择要上传的文件')
        return false
      }
      const formData = new FormData()
      console.log(this.reportId)
      formData.append('file', this.file)
      this.handleImportExcel(formData)
    },
    // 导入
    handleImportExcel(data){
      data.append('reportId',this.reportId) // 上传时携带的其他参数
      EpaWeekly.uploadExcel(data).then((res)=>{
        if(res.result>0){
          this.$message.success("导入成功")
          this.visibleImport = false
          this.$emit('Refresh');
        }
      })
    },
    open(reportId){
      console.log(reportId)
      this.reportId=reportId;
      console.log(this.reportId)
      this.visibleImport = true;
    },
    // 取消
    importXlsErr() {
      this.file=null;
      this.visibleImport = false
    },
    // 上传之前
    beforeUpload(file, fileList) {
      console.log('fileList', file)
      this.fileName = file.name
      this.file = file
      return false
    },
    // 隐藏上传文件的显示
    hideFileName() {
      this.fileName = ''
      this.file = null
    }
  }
}
</script>

<style scoped>

</style>